'''
Created on Apr 1, 2012

@author: Johnathon
'''
import Zero, One, DNot, sys

D = sys.modules[globals()['__name__']]


def AND(other):
        if not other.isLineValue():
            raise Exception("Tried to 'AND' something that isn't a subclass of LineValue")
        if other is D:
            return D
        elif other is DNot:
            return Zero
        else:
            return other.AND(D)
    
def OR(other):
        if not other.isLineValue():
            raise Exception("Tried to 'OR' something that isn't a subclass of LineValue")
        if other is D:
            return D
        elif other is DNot:
            return One
        else:
            return other.OR(D)
        
def XOR(other):
        if not other.isLineValue():
            raise Exception("Tried to 'XOR' something that isn't a subclass of LineValue")
        if other is D:
            return Zero
        elif other is DNot:
            return One
        else:
            return other.XOR(D)
    
def NOT():
    return DNot

def isLineValue():
    return True

def __repr__():
    return "D"

def __str__():
    return "D"